package org.water.config;

import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import net.sf.ehcache.CacheManager;

@Configuration
public class CacheConfig {

	
	@Bean
	public EhCacheManagerFactoryBean ehcacheManagerFactory()
	{
		EhCacheManagerFactoryBean bean=new EhCacheManagerFactoryBean();
		bean.setConfigLocation((Resource) new ClassPathResource("ehcache/ehcache-shiro.xml") );
		return bean;
	}
	@Bean
	public EhCacheManager cacheManager(CacheManager ehcacheManagerFactory)
	{
		EhCacheManager cacheManager=new EhCacheManager();
		cacheManager.setCacheManager(ehcacheManagerFactory);
		return cacheManager;
	}
	@Bean
	public EhCacheCacheManager springCacheManager(CacheManager ehcacheManagerFactory)
	{
		return new EhCacheCacheManager(ehcacheManagerFactory);
	}
}
